<?php

namespace App\Http\Requests\Game\Config\Betting;

use App\Http\Requests\Request;

class SaveRequest extends Request
{

    /**
     * 应用于请求的验证规则。
     *
     * @return array
     */
    public function rules()
    {
        return [
            'game_id' => 'required|string',
            'config.globals.bet_type' => 'required|integer',
            'config.globals.bet1.*.currency' => 'nullable|required_if:config.globals.bet_type,1|string',
            'config.globals.bet1.*.gear.*' => 'nullable|required_if:config.globals.bet_type,1|numeric|min:0',
            'config.globals.bet1' => ['nullable', 'array', function ($attribute, $items, $fail) {
                if (count($items) != count(array_unique(array_column($items, 'currency')))) {
                    $fail(trans('validation.unique_value'));
                }
            }],
            'config.globals.bet2.*.currency' => 'nullable|required_if:config.globals.bet_type,2|string',
            'config.globals.bet2.*.gear.*' => 'nullable|required_if:config.globals.bet_type,2|numeric|min:0',
            'config.globals.bet2' => ['nullable', 'array', function ($attribute, $items, $fail) {
                if (count($items) != count(array_unique(array_column($items, 'currency')))) {
                    $fail(trans('validation.unique_value'));
                }
            }],
        ];
    }

    /**
     * 自定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [];
    }

    /**
     * 自定义字段名称。
     *
     * @return array
     */
    public function attributes()
    {
        return [];
    }
}
